<?php

require_once('../../espace_administration/Controller/UserController.php');

function CheckUser($login,$sha1)
{
  $userHandler = new UserController();
  echo 'call to check user';
  if ( $userHandler->userHasCredential($login, $sha1) )
    return true;
  return false;
}
  echo 'Start auth()';
if(!isset($_POST['sha1']))
{
  header("Location: ../../../index2.php");
  die();
}
$sha1=$_POST['sha1'];

if(!isset($_POST['email']))
{
  header("Location: ../../../index2.php");
  die();
}
$login=$_POST['email'];

if(!CheckUser($login,$sha1))
{
  header("Location: ../../../index2.php");
  die();
}

session_start();

$_SESSION['last_access']=time();
$_SESSION['ipaddr']=$_SERVER['REMOTE_ADDR'];
$_SESSION['user']=$login;

header("Location: ../espace_client.php?onglet=espace_client&page=accueil_espace_client");

